package com.leetcode.LC;

import java.util.HashMap;

public class LC1624 {
    public int maxLengthBetweenEqualCharacters(String s) {

        int max = -1;
        HashMap<Character, int[]> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (map.containsKey(s.charAt(i))) {
                int[] ints = map.get(s.charAt(i));
                ints[1] = i;
                max = Math.max(max, ints[1] - ints[0] - 1);
                map.put(s.charAt(i), ints);
            } else {
                map.put(s.charAt(i), new int[]{i, i});
            }
        }
        return max;
    }
}
